
pkgname=wireless-regdb
pkgver=2018.05.31
pkgrel=1
pkgdesc="Central Regulatory Domain Database"
arch=('x86_64')
url="https://wireless.kernel.org/en/developers/Regulatory/CRDA"
backup=(etc/conf.d/wireless-regdom)
license=('custom')
depends=('sh')
makedepends=('crda')
install=wireless-regdb.install
source=("https://www.kernel.org/pub/software/network/${pkgname}/${pkgname}-${pkgver}.tar.xz"
        'crda.conf.d')
sha256sums=('e1dfbc3b97771373077f430c3c05082fae883145b37db5b2cfd12c56676fbe7b'
            '192428fd959806705356107bffc97b8b379854e79bd013c4ee140e5202326e2b')

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install
  
  install -D -m644 ${srcdir}/${pkgname}-${pkgver}/sforshee.key.pub.pem ${pkgdir}/usr/lib/crda/pubkeys/sforshee.key.pub.pem
  install -D -m644 ${srcdir}/${pkgname}-${pkgver}/regulatory.bin.5 ${pkgdir}/usr/share/man/man5/regulatory.bin.5
  
  install -D -m644 ${srcdir}/crda.conf.d ${pkgdir}/etc/conf.d/wireless-regdom
  for dom in $(grep ^country ${srcdir}/${pkgname}-${pkgver}/db.txt | cut -d' ' -f2 | sed 's|:||g'); do
    echo "#WIRELESS_REGDOM=\"${dom}\"" >> ${pkgdir}/etc/conf.d/wireless-regdom.tmp
  done
  sort -u ${pkgdir}/etc/conf.d/wireless-regdom.tmp >> ${pkgdir}/etc/conf.d/wireless-regdom
  rm -f ${pkgdir}/etc/conf.d/wireless-regdom.tmp

  install -D -m644 ${srcdir}/${pkgname}-${pkgver}/LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/LICENSE
}
